from rest_framework import viewsets
from rest_framework.permissions import AllowAny

from .models import Area
from .serializers import AreaSerializer, AreaListSerializer
from ..common.paginator import MyPageNumberPagination


class AreaViewSet(viewsets.ReadOnlyModelViewSet):
    """
    内容视图集，提供内容的CRUD操作。
    """
    queryset = Area.objects.all()
    permission_classes = [AllowAny]
    pagination_class = MyPageNumberPagination

    def get_serializer_class(self):
        """
        根据请求的动作返回不同的序列化器。
        """
        if self.action == 'list':
            return AreaListSerializer
        return AreaSerializer
